home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / ip.h < prev    next >
C/C++ Source or Header  |  1994-09-16  |  7KB  |  220 lines

  1. /*
  2.     -----------------------------------------------------
  3.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  4.  
  5.     __asm added for lcsum prototype
  6.     -----------------------------------------------------
  7. */
  8.  
  9. #ifndef    _IP_H
  10. #define    _IP_H
  11.  
  12. #ifndef    _GLOBAL_H
  13. #include "global.h"
  14. #endif
  15.  
  16. #ifndef    _MBUF_H
  17. #include "mbuf.h"
  18. #endif
  19.  
  20. #ifndef    _IFACE_H
  21. #include "iface.h"
  22. #endif
  23.  
  24. #ifndef    _INTERNET_H
  25. #include "internet.h"
  26. #endif
  27.  
  28. #ifndef    _TIMER_H
  29. #include "timer.h"
  30. #endif
  31.  
  32. #define TLB        30    /* Default reassembly timeout, sec */
  33. #define    IPVERSION    4
  34. #define IP_CS_OLD    1    /* use saved checksum */
  35. #define IP_CS_NEW    0    /* calculate checksum */
  36.  
  37. extern char Hashtab[];    /* Modulus lookup table */
  38.  
  39. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  40. extern struct mib_entry Ip_mib[];
  41. #define    ipForwarding        Ip_mib[1].value.integer
  42. #define    ipDefaultTTL        Ip_mib[2].value.integer
  43. #define    ipInReceives        Ip_mib[3].value.integer
  44. #define    ipInHdrErrors        Ip_mib[4].value.integer
  45. #define    ipInAddrErrors        Ip_mib[5].value.integer
  46. #define    ipForwDatagrams        Ip_mib[6].value.integer
  47. #define    ipInUnknownProtos    Ip_mib[7].value.integer
  48. #define    ipInDiscards        Ip_mib[8].value.integer
  49. #define    ipInDelivers        Ip_mib[9].value.integer
  50. #define    ipOutRequests        Ip_mib[10].value.integer
  51. #define    ipOutDiscards        Ip_mib[11].value.integer
  52. #define    ipOutNoRoutes        Ip_mib[12].value.integer
  53. #define    ipReasmTimeout        Ip_mib[13].value.integer
  54. #define    ipReasmReqds        Ip_mib[14].value.integer
  55. #define    ipReasmOKs        Ip_mib[15].value.integer
  56. #define    ipReasmFails        Ip_mib[16].value.integer
  57. #define    ipFragOKs        Ip_mib[17].value.integer
  58. #define    ipFragFails        Ip_mib[18].value.integer
  59. #define    ipFragCreates        Ip_mib[19].value.integer
  60.  
  61. #define    NUMIPMIB    19
  62.  
  63. /* IP header, INTERNAL representation */
  64. #define IPLEN        20    /* Length of standard IP header */
  65. #define IP_MAXOPT    40    /* Largest option field, bytes */
  66. struct ip {
  67.     int32 source;        /* Source address */
  68.     int32 dest;        /* Destination address */
  69.     int16 length;        /* Total length */
  70.     int16 id;        /* Identification */
  71.     int16 offset;        /* Fragment offset in bytes */
  72.     int16 checksum;        /* Header checksum */
  73.  
  74.     struct {
  75.         char congest;    /* Congestion experienced bit (exp) */
  76.         char df;    /* Don't fragment flag */
  77.         char mf;    /* More Fragments flag */
  78.     } flags;
  79.  
  80.     char version;        /* IP version number */
  81.     char tos;        /* Type of service */
  82.     char ttl;        /* Time to live */
  83.     char protocol;        /* Protocol */
  84.     char optlen;        /* Length of options field, bytes */
  85.     char options[IP_MAXOPT];/* Options field */
  86. };
  87. #define    NULLIP    (struct ip *)0
  88.  
  89. /* Fields in option type byte */
  90. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  91. #define    OPT_CLASS    0x60    /* Option class */
  92. #define    OPT_NUMBER    0x1f    /* Option number */
  93.  
  94. /* IP option numbers */
  95. #define    IP_EOL        0    /* End of options list */
  96. #define    IP_NOOP        1    /* No Operation */
  97. #define    IP_SECURITY    2    /* Security parameters */
  98. #define    IP_LSROUTE    3    /* Loose Source Routing */
  99. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  100. #define    IP_RROUTE    7    /* Record Route */
  101. #define    IP_STREAMID    8    /* Stream ID */
  102. #define    IP_SSROUTE    9    /* Strict Source Routing */
  103.  
  104. /* Timestamp option flags */
  105. #define    TS_ONLY        0    /* Time stamps only */
  106. #define    TS_ADDRESS    1    /* Addresses + Time stamps */
  107. #define    TS_PRESPEC    3    /* Prespecified addresses only */
  108.  
  109. /* IP routing table entry */
  110. struct route {
  111.     struct route *prev;    /* Linked list pointers */
  112.     struct route *next;
  113.     int32 target;        /* Target IP address */
  114.     unsigned int bits;    /* Number of significant bits in target */
  115.     int32 gateway;        /* IP address of local gateway for this target */
  116.     int32 metric;        /* Hop count or whatever */
  117.     struct iface *iface;    /* Device interface structure */
  118.     int flags;
  119. #define    RTPRIVATE    0x1    /* Should the world be told of this route ? */
  120. #define    RTTRIG    0x2        /* Trigger is pending for this route */
  121.     struct timer timer;    /* Time until aging of this entry */
  122.     int32 uses;        /* Usage count */
  123. };
  124. #define    NULLROUTE    (struct route *)0
  125. extern struct route *Routes[32][HASHMOD];    /* Routing table */
  126. extern struct route R_default;            /* Default route entry */
  127.  
  128. /* Cache for the last-used routing entry, speeds up the common case where
  129.  * we handle a burst of packets to the same destination
  130.  */
  131. struct rt_cache {
  132.     int32 target;
  133.     struct route *route;
  134. };
  135. extern struct rt_cache Rt_cache;
  136.  
  137. /* Reassembly descriptor */
  138. struct reasm {
  139.     struct reasm *next;    /* Linked list pointer */
  140.     struct timer timer;    /* Reassembly timeout timer */
  141.     struct frag *fraglist;    /* Head of data fragment chain */
  142.     int16 length;        /* Entire datagram length, if known */
  143.     int32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  144.     int32 dest;
  145.     int16 id;
  146.     char protocol;
  147. };
  148. #define    NULLREASM    (struct reasm *)0
  149.  
  150. /* Fragment descriptor in a reassembly list */
  151. struct frag {
  152.     struct frag *prev;    /* Previous fragment on list */
  153.     struct frag *next;    /* Next fragment */
  154.     struct mbuf *buf;    /* Actual fragment data */
  155.     int16 offset;        /* Starting offset of fragment */
  156.     int16 last;        /* Ending offset of fragment */
  157. };
  158. #define    NULLFRAG    (struct frag *)0
  159.  
  160. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  161.  
  162. /* Structure for handling raw IP user sockets */
  163. struct raw_ip {
  164.     struct raw_ip *next;    /* Linked list pointer */
  165.  
  166.     struct mbuf *rcvq;    /* receive queue */
  167.     void (*r_upcall) __ARGS((struct raw_ip *));
  168.     int protocol;        /* Protocol */
  169.     int user;        /* User linkage */
  170. };
  171. #define    NULLRIP    ((struct raw_ip *)0)
  172. extern struct raw_ip *Raw_ip;
  173.  
  174. /* Transport protocol link table */
  175. struct iplink {
  176.     char proto;
  177.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  178. };
  179. extern struct iplink Iplink[];
  180.  
  181. /* In ip.c: */
  182. void ip_garbage __ARGS((int drastic));
  183. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  184.     int rxbroadcast));
  185. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  186.     int rxbroadcast));
  187. int ip_send __ARGS((int32 source,int32 dest,char protocol,char tos,char ttl,
  188.     struct mbuf *bp,int16 length,int16 id,char df));
  189. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  190. void del_ip __ARGS((struct raw_ip *rrp));
  191.  
  192. /* In iproute.c: */
  193. void ipinit __ARGS((void));
  194. int16 ip_mtu __ARGS((int32 addr));
  195. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  196.     int prec,int del,int tput,int rel));
  197. int ip_route __ARGS((struct iface *i_iface,struct mbuf *bp,int rxbroadcast));
  198. int32 locaddr __ARGS((int32 addr));
  199. void rt_merge __ARGS((int trace));
  200. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  201.     struct iface *iface,int32 metric,int32 ttl,char private));
  202. int rt_drop __ARGS((int32 target,unsigned int bits));
  203. struct route *rt_lookup __ARGS((int32 target));
  204. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  205.  
  206. /* In iphdr.c: */
  207. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int16 len));
  208. int16 eac __ARGS((int32 sum));
  209. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  210. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  211.  
  212. /* In either lcsum.c or pcgen.asm: */
  213. #ifndef ATARI
  214. int16 lcsum __ARGS((int16 *wp,int16 len));
  215. #else
  216. int16 __asm lcsum(int16 *wp, int16 len);
  217. #endif
  218.  
  219. #endif /* _IP_H */
  220.